<div class="form-tabs {{ field.class }}">

{% if uri.params.tab %}
    {% set active = uri.params.tab %}
{% elseif field.active %}
    {% set active = field.active %}
{% else %}
    {% set active = 1 %}
{% endif %}

{% if field.fields %}
    {% set storedValue = get_cookie('grav-tabs-state')|default('{}')|json_decode %}
    {% set tabsKey = field.fields|keys|join('.') %}
    {% for tab in field.fields %}
        {% if tab.type == 'tab' and (tab.security is empty or authorize(array(tab.security))) %}
        <input type="radio" name="tab-{{ tabsKey }}" id="tab-{{ tabsKey ~ loop.index }}" value="{{ (scope ~ tab.name) }}" class="tab-head no-form" {{ ((attribute(storedValue, 'tab-' ~ tabsKey) == scope ~ tab.name) or active == loop.index) ? 'checked="checked"' : '' }}/>
        <label for="tab-{{ tabsKey ~ loop.index }}">
            {% if grav.twig.twig.filters['tu'] is defined %}{{ tab.title|tu }}{% else %}{{ tab.title|t }}{% endif %}
        </label>
        {% endif %}
    {% endfor %}
    <div class="tab-body-wrapper">
        {% for field in field.fields %}
            {% if field.type == 'tab' %}
                {% if field.security is empty or authorize(array(field.security)) %}
                    {% set value = data.value(field.name) %}
                    <div id="tab-body-{{ tabsKey ~ loop.index }}" class="tab-body">
                        {% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
                    </div>
                {% endif %}
            {% endif %}
        {% endfor %}
    </div>
{% endif %}
</div>

